import React from 'react'
import Tit from '../../components/Tit'
import Address from '../../components/Address'
import { Picker, List, InputItem } from 'antd-mobile'
import { withRouter } from 'react-router-dom'
import './ReturnOrder.less'
class RetornOrder extends React.Component {
    state = {
        cols: 1,
        data: [],
        asyncValue: [],
        seasons: null,
        Address: null,
        wuNo: '',
        companyId: [],
    }
    onPickerChange = (val) => {
        console.log(val);
    }
    componentDidMount() {
        this.$postData('/api/order/allLogistics', {}, params => {
            console.log(params)
            switch (params.code) {
                case 100:
                    var a = []
                    params.data.map((val) => {
                        a.push({ 'label': val.customerName, value: val.id })
                    })
                    this.setState({
                        seasons: [a]
                    })
                    break;
                default:
                    this.Toast.info(params.msg);
                    break;
            }
        })
        this.$postData('/api/order/getReturnInfo', {}, params => {
            console.log(params)
            switch (params.code) {
                case 100:
                    this.setState({
                        Address: params.data
                    })
                    break;
                default:
                    this.Toast.info(params.msg);
                    break;
            }
        })
    }
    RetOrder = () => {
        if (this.state.companyId.length === 0) {
            return
        }
        console.log(this.state.companyId, this.state.wuNo, this.props)
        this.$postData('/api/order/saveWInfo', { id: this.props.match.params.id, companyId: this.state.companyId[0], wuNo: this.state.wuNo },
            (params) => {
                switch (params.code) {
                    case 100:
                        this.Toast.info(params.msg);
                        this.props.history.goBack()
                        break;
                    default:
                        this.Toast.info(params.msg);
                        this.props.history.goBack()
                        break;
                }
            })
    }
    render() {
        return (
            <div className='Return-d1'>
                <Tit zz={true} tit={'填写物流信息'}></Tit>
                {this.state.Address ? <div className='FillO-page Address-white'><Address ID={2} index={0} address={this.state.Address}></Address></div> : <div></div>}
                {this.state.seasons ? <Picker
                    className='ROr-d1'
                    data={this.state.seasons}
                    cascade={false}
                    extra="请选择"
                    value={this.state.companyId}
                    onChange={v => this.setState({ companyId: v })}
                    onOk={v => this.setState({ companyId: v })}
                >
                    <List.Item arrow="horizontal">快递名称</List.Item>
                </Picker> : <div></div>}
                <div className='xian'></div>
                <InputItem
                    className='ROr-d2'
                    type="number"
                    placeholder="请输入快递号"
                    value={this.state.wuNo}
                    onChange={v => this.setState({ wuNo: v })}
                    maxLength='50'
                >快递编号</InputItem>
                <div className='center ROr-d3' onClick={this.RetOrder}>提交</div>
            </div>
        )
    }
}

export default withRouter(RetornOrder)